package demo4;

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * max increasing subsequence
     * @param arr int整型一维数组 the array
     * @return int整型
     */
    public int MLS (int[] arr) {
        // write code here
        int n = arr.length;
        int ret = 0;
        Arrays.sort(arr);
        int[] nums = new int[n];
        int index = 0;
        int i = 0;
        while(i<n) {
            nums[index++] = arr[i];
            while(i+1 < n && arr[i] == arr[i+1]) {
                i++;
            }
            i++;
        }
        i = 0;
        while(i<index) {
            int j = i+1;
            while(j<index && nums[j-1]+1 == nums[j]) {
                j++;
            }
            ret = Math.max(ret, j-i);
            i = j;
        }
        return ret;
    }
}